<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/4/28
  Time: 9:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="com.cnplan.core.Constant" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!doctype html>
<html>

<%@include file="../../layout/css.jsp" %>

<body class="page-container-bg-solid">
<div class="page-wrapper">
    <div class="page-wrapper-row">
        <div class="page-wrapper-top">
            <div class="page-header">
                <%@include file="../../layout/nav-topmenu.jsp" %>
            </div>
        </div>
    </div>
    <div class="page-wrapper-row full-height">
        <div class="page-wrapper-middle">
            <div class="page-content">
                <div class="container-fluid">
                    <ul class="page-breadcrumb breadcrumb">
                        <li>
                            <span>&nbsp;&nbsp;</span>
                            <a href="${pageContext.request.contextPath}/">首页</a>
                            <i class="fa fa-chevron-right"></i>
                        </li>
                        <li>
                            <span>账户信息</span>
                        </li>
                    </ul>
                    <div class="row">
                        <div class="col-md-12">
                            <div class="portlet light">
                                <div class="portlet-title">
                                    <div class="caption">
                                        <i class="icon-user font-green"></i>
                                        <span class="caption-subject bold font-green">&nbsp;${title}编辑</span>
                                    </div>
                                </div>
                                <div class="portlet-body form">
                                    <form id="my-form" class="form-horizontal" role="form"
                                          action="${pageContext.request.contextPath}/auth/user/manage"
                                          method="post">
                                        <div class="form-body">
                                            <input type="hidden" id="id" name="id"
                                                   value="${record.id}"/>
                                            <div class="form-group">
                                                <label class="col-md-3 control-label">用 户 名</label>
                                                <div class="col-md-9">
                                                    <input type="text"
                                                           value="${record.userName}"
                                                           class="form-control input-inline input-large"
                                                           name="userName" readonly/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-3 control-label">真实姓名</label>
                                                <div class="col-md-9">
                                                    <input type="text" value="${record.realName}"
                                                           class="form-control input-inline input-large"
                                                           name="realName" readonly/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-3 control-label">所在部门</label>
                                                <div class="col-md-9">
                                                    <input type="text"
                                                           value="${record.deptName}"
                                                           class="form-control input-inline input-large"
                                                           name="deptName"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-3 control-label">手机号码</label>
                                                <div class="col-md-9">
                                                    <input type="text"
                                                           value="${record.phone}"
                                                           class="form-control input-inline input-large"
                                                           name="phone"/>
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-md-3 control-label">邮箱地址</label>
                                                <div class="col-md-9">
                                                    <input type="text"
                                                           value="${record.email}"
                                                           class="form-control input-inline input-large"
                                                           name="email"/>
                                                </div>
                                            </div>
                                        </div>

                                        <div class="form-actions">
                                            <div class="row">
                                                <div class="col-md-offset-3 col-md-9">
                                                    <a class="btn blue" href="#" data-toggle="modal"
                                                       data-target="#modal_changePwd">修改密码</a>
                                                    <button type="submit" class="btn green-meadow">提交</button>
                                                    <%
                                                        String fromUrl = request.getSession().getAttribute(Constant.FROM_URL) == null ? request.getHeader("Referer") : request.getSession().getAttribute(Constant.FROM_URL).toString();
                                                    %>
                                                    <a class="btn default" href="<%=fromUrl%>">返回</a>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_changePwd" tabindex="-1" role="dialog" aria-labelledby="modal_label">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="modal_label">修改登录密码</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" onsubmit="return false">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">原密码</label>

                        <div class="col-sm-9">
                            <input type="password" class="form-control input-inline input-large"
                                   id="oriPwd" name="oriPwd" placeholder="" value="">
                            <span style="color: red;">*</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">新密码</label>

                        <div class="col-sm-9">
                            <input type="password" class="form-control input-inline input-large"
                                   id="newPwd" name="newPwd" placeholder="" value="">
                            <span style="color: red;">*</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">确认密码</label>

                        <div class="col-sm-9">
                            <input type="password" class="form-control input-inline input-large"
                                   id="renewPwd" name="renewPwd" placeholder="" value="">
                            <span style="color: red;">*</span>
                        </div>
                    </div>

                    <hr/>

                    <div class="form-group">
                        <div class="col-sm-9 col-sm-offset-3">
                            <button type="button" class="btn green-meadow" onclick="changePwd()">确 认</button>
                            <button type="button" class="btn default" data-dismiss="modal">关 闭</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<%@include file="../../layout/footer.jsp" %>
</div>

<%@include file="../../layout/script.jsp" %>

<script>
    $(function () {
        $("#my-form").ajaxForm({
            dataType: 'json',
            success: function (data) {
                if (data['code'] === 200) {
                    toastr.success(data['message']);
                } else {
                    toastr.error(data['message']);
                }
            }
        });
    });

    function changePwd() {
        var userId = $("#id").val();
        var oriPwd = $("#oriPwd").val();
        var newPwd = $("#newPwd").val();
        var renewPwd = $("#renewPwd").val();

        if (oriPwd === null || oriPwd === undefined || oriPwd.trim() === '') {
            alert("原密码不能为空，请重新输入！");
            return;
        }

        if (newPwd === null || newPwd === undefined || newPwd.trim() === '') {
            alert("新密码不能为空，请重新输入！");
            return;
        }

        if (renewPwd === null || renewPwd === undefined || renewPwd.trim() === '') {
            alert("确认密码不能为空，请重新输入！");
            return;
        }

        if (newPwd !== renewPwd) {
            toastr.warning("确认密码与新密码不一致，请重新输入！");
            return;
        }

        $.post("/auth/user/changePassword", {
            id: userId,
            oriPwd: oriPwd,
            newPwd: newPwd
        }, function (data) {
            if (data['code'] === 200) {
                $('#modal_changePwd').modal('hide');
                toastr.success(data['message']);
            } else {
                toastr.error(data['message']);
            }
        }, 'json');
    }
</script>
</body>
</html>
